#pragma once

class CommandSettingsDialog : public ATL::CDialogImpl<CommandSettingsDialog>
{
private:
	WTL::CEdit _textControl;
	WTL::CButton _useSendMessageControl;
	WTL::CButton _parseTextControl;

	CommandSettings _settings;

public:
	enum { IDD = IDD_COMMANDSETTINGS };

	BEGIN_MSG_MAP(CommandSettingsDialog)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_RANGE_HANDLER(IDOK, IDNO, OnCloseCmd)
	END_MSG_MAP()

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		_textControl = GetDlgItem(IDC_TEXT);
		_useSendMessageControl = GetDlgItem(IDC_USESEND);
		_parseTextControl = GetDlgItem(IDC_PARSETEXT);

		_textControl.AppendText(_settings.Text, TRUE);
		_useSendMessageControl.SetCheck(_settings.UseSendMessage ? BST_CHECKED : BST_UNCHECKED);
		_parseTextControl.SetCheck(_settings.ParseText ? BST_CHECKED : BST_UNCHECKED);

		return TRUE;
	}

	LRESULT OnCloseCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		if(wID == IDOK)
		{
			wchar_t buff[1000];
			int copied = _textControl.GetLine(0, buff, 1000);

			ATL::CString text;
			text.Append(buff, copied);

			_settings.Text = text;
			_settings.UseSendMessage = (_useSendMessageControl.GetCheck() == BST_CHECKED);
			_settings.ParseText = (_parseTextControl.GetCheck() == BST_CHECKED);
		}
		::EndDialog(m_hWnd, wID);
		return 0;
	}

	void SetData(const CommandSettings& settings)
	{
		_settings = settings;
	}

	void GetData(CommandSettings& settings)
	{
		settings = _settings;
	}

};
